<!DOCTYPE html>
<html>
<head>
    <!-- 设置字符编码 -->
    <meta charset="UTF-8">
    <!-- 禁止移动端页面缩放 -->
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
    <!-- 阻止浏览器缓存页面内容 -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=8">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">

    <title>发布动态</title>
</head>
<body>
    <script>
        let value = localStorage.getItem("jwt");
        console.log(value);
        
        check_login(value);

        function check_login(value) {
            const xhr = new XMLHttpRequest();
            xhr.open('post', '/users/login_again', true);
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.setRequestHeader('authorization', value);
            xhr.onreadystatechange = function(e) {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        let response = JSON.parse(xhr.response);
                        console.log(response);
                        if (response.login) {
                            let new_html = response.new_html;
                            // 显示真正主页的内容
                            get_main_page(new_html);
                        } else {
                            // 跳转到登录页
                            window.location.href = '/login.html';
                        }
                    }
                }
            }
            xhr.send("");
        }

        function get_main_page(page_html) {
            document.open();
            document.write(page_html);
            document.close();
        }
    </script>
</body>
</html>
